/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import database_beans.Student;
import database_beans.Zaposleni;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.hibernate.HibernateException;
import server.AdminLogic;

/**
 *
 * @author stefan
 */
@ManagedBean
@SessionScoped
public class AdminDodaj {

    private Student student;
    private Zaposleni zaposlen;

    public AdminDodaj() {
        this.student = new Student();
        this.zaposlen = new Zaposleni();
    }

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    public Zaposleni getZaposlen() {
        return zaposlen;
    }

    public void setZaposlen(Zaposleni zaposlen) {
        this.zaposlen = zaposlen;
    }

    public String dodajStudenta() {

        try {
            AdminLogic.getInstance().snimiStudenta(student);
        } catch (HibernateException e) {
            String errorMessage = "Vec postoji student sa unetim korisnickim imenom";
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(errorMessage));
            return "dodajStudenta";
        }
        return "welcomePrimefaces";
    }

    public String dodajZaposlenog(){

//        try {
//            AdminLogic.getInstance().dodajZaposlenog(zaposlen);
//        } catch (PiaDatabseColumnExistsHibernateException e) {
//            System.out.println("Vec postoji");
//            String errorMessage = "Vec postoji zaposleni sa unetim korisnickim imenom";
//            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(errorMessage));
//            return "dodajZaposlenog";
//
//        }
        return "welcomePrimefaces";
    }

}
